home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
withbe.pqs
/
withbe.pas
Wrap
Pascal/Delphi Source File
|
1985-08-03
|
6KB
|
218 lines
program withbench;
{ program to benchmark the WITH statement
IBM PC specific.
The timer routines would have to be replaced for a different machine.
}
const NumIter = 1000; { actual number is NumIter ** 2 }
type TimerType = record
low, high : integer
end;
var StartTime, EndTime : TimerType;
LoopOverhead : Real;
Ix1, Ix2 : integer;
CTime : Real;
n : integer;
{----- variables referenced used in the benchmark itself }
type AType = record
A1, A2 : integer
end;
BType = array [1..10] of record
B1, B2 : integer
end;
var AData : AType;
BData : BType;
var APtr : ^AType;
BPtr : ^BType;
procedure GetTime(var t : TimerType);
{ NOTE: The techniqe used by this routine is quick, but totally incompatible }
var BiosTimer : TimerType absolute $40:$6C;
begin
Inline($FA); { disable interrupts }
t := BiosTimer;
Inline($FB) { enable interrupts }
end;
function CalcElapsed : real;
function TimerToReal(t : TimerType) : Real;
const TimerUnit = 18.2;
RealAdj = 65536.0;
var r : real;
begin
r := (t.high * RealAdj) + t.low;
if t.low < 0 then r := r + RealAdj;
TimerToReal := r / TimerUnit
end;
begin { CalcElapsed }
CalcElapsed := TimerToReal(EndTime) - TimerToReal(StartTime)
end;
function CalcTime : Real;
begin
CalcTime := (CalcElapsed - LoopOverhead) / (Int(NumIter) * Int(NumIter))
end;
begin
ClrScr;
writeln('Benchmark: WITH Statement');
writeln;
{ calculate the loop overhead }
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
end;
GetTime(EndTime);
LoopOverhead := CalcElapsed;
writeln('Loop overhead = ', LoopOverhead:18:9);
{ simple assignment, using WITH }
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
with AData do begin
A1 := 1
end
end;
GetTime(EndTime);
CTime := CalcTime;
writeln('WITH AData DO A1 := 1 ', CTime:18:9);
{ like above, but do not count the overhead for the WITH statement itself }
GetTime(StartTime);
with AData do
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
A1 := 1
end;
GetTime(EndTime);
CTime := CalcTime;
writeln(' A1 := 1 ', CTime:18:9);
{ simple assignment, no WITH }
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
AData.A1 := 1
end;
GetTime(EndTime);
CTime := CalcTime;
writeln('AData.A1 := 1 ', CTime:18:9);
{ using WITH, data on heap }
New(APtr);
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
with APtr^ do begin
A1 := 1
end
end;
GetTime(EndTime);
CTime := CalcTime;
writeln('WITH APtr^ DO A1 := 1 ', CTime:18:9);
{ like above, but don't count the WITH statement itself }
with APtr^ do begin
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
A1 := 1
end
end;
GetTime(EndTime);
CTime := CalcTime;
writeln(' A1 := 1 ', CTime:18:9);
{ no WITH, data on heap }
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
APtr^.A1 := 1
end;
GetTime(EndTime);
CTime := CalcTime;
writeln('APtr^.A1 := 1 ', CTime:18:9);
{ array element assignment, using WITH }
n := 1;
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
with BData[n] do begin
B1 := 1
end
end;
GetTime(EndTime);
CTime := CalcTime;
writeln('WITH BData[n] DO B1 := 1 ', CTime:18:9);
{ like above, but don't count the WITH statement }
with BData[n] do begin
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
B1 := 1
end
end;
GetTime(EndTime);
CTime := CalcTime;
writeln(' B1 := 1 ', CTime:18:9);
{ array element assignment, no WITH }
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
BData[n].B1 := 1
end;
GetTime(EndTime);
CTime := CalcTime;
writeln('BData[n].B1 := 1 ', CTime:18:9);
{ array element assignment using WITH, data on heap }
New(BPtr);
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
with BPtr^[n] do begin
B1 := 1
end
end;
GetTime(EndTime);
CTime := CalcTime;
writeln('WITH BPtr^[n] DO B1 := 1 ', CTime:18:9);
{ like about, but dont count the WITH statement }
with BPtr^[n] do begin
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
B1 := 1
end
end;
GetTime(EndTime);
CTime := CalcTime;
writeln(' B1 := 1 ', CTime:18:9);
{ array element assignment, no WITH, data on heap }
GetTime(StartTime);
for Ix1 := 1 to NumIter do
for Ix2 := 1 to NumIter do begin
BPtr^[n].B1 := 1
end;
GetTime(EndTime);
CTime := CalcTime;
writeln('BPtr^[n].B1 := 1 ', CTime:18:9);
end.